//
//  NSString+Helper.m
//  NJUSTHelper
//
//  Created by 郑越辉 on 2017/9/21.
//  Copyright © 2017年 njust. All rights reserved.
//

#import "NSString+Helper.h"

@implementation NSString (Helper)

+(NSString *)weekStringWithDate:(NSDate *) date{
    NSDateFormatter  *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];//解决8小时时间差问题
    [dateFormatter setDateFormat:@"EEE"];
    return [dateFormatter stringFromDate:date];
    
}


+(NSString *)yearStringWithDate:(NSDate *) date{
    NSDateFormatter  *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];//解决8小时时间差问题
    [dateFormatter setDateFormat:@"yyy"];
    return [dateFormatter stringFromDate:date];
    
}

+(NSString *)monthStringWithDate:(NSDate *) date{
    NSDateFormatter  *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];//解决8小时时间差问题
    [dateFormatter setDateFormat:@"MM"];
    return [dateFormatter stringFromDate:date];
}

+(NSString *)dayStringWithDate:(NSDate *) date{
    NSDateFormatter  *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];//解决8小时时间差问题
    [dateFormatter setDateFormat:@"dd"];
    return [dateFormatter stringFromDate:date];
}

+(int) indexOfWeekString:(NSString *)weekStr{
    int day = 0;
    if ([weekStr  isEqual: @"周一"] || [weekStr  isEqual: @"Mon"]) {
        day = 0;
    } else if ([weekStr isEqual:@"周二"] || [weekStr  isEqual: @"Tue"]) {
        day = 1;
    } else if ([weekStr isEqual:@"周三"] || [weekStr  isEqual: @"Wed"]) {
        day = 2;
    } else if ([weekStr isEqual:@"周四"] || [weekStr  isEqual: @"Thu"]) {
        day = 3;
    } else if ([weekStr isEqual:@"周五"] || [weekStr  isEqual: @"Fri"]) {
        day = 4;
    } else if ([weekStr isEqual:@"周六"] || [weekStr  isEqual: @"Sat"]) {
        day = 5;
    } else if ([weekStr isEqual:@"周日"] || [weekStr  isEqual: @"Sun"]) {
        day = 6;
    }
    return day;
}
+(NSString *)nullString:(NSString *)str RepleseWith:(NSString *)rep{
    if([str length] == 0) {
        return rep;
    }else{
        return str;
    }
}

@end
